﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RegisterationCommon.Common;
using System.Data;

namespace RegisterationCommon.Education
{
    /// <summary>
    /// 教育局角色实体类
    /// </summary>
    public class EduRole
    {
        #region 局部变量
        //主键，自动编号
        private int _ID = 0;
        //角色名称
        private string _RoleName = "";
        //角色权限
        private string _RolePM = "";
        //是否禁用(0正常1禁用)
        private bool _IsDisable = false;
        #endregion
        
        #region 属性列表
        /// <summary>
        /// 是否禁用(0正常1禁用)
        /// </summary>
        public bool IsDisable
        {
            get { return _IsDisable; }
            set { _IsDisable = value; }
        }
        /// <summary>
        /// 角色权限
        /// </summary>
        public string RolePM
        {
            get { return _RolePM; }
            set { _RolePM = value; }
        }
        /// <summary>
        /// 角色名称
        /// </summary>
        public string RoleName
        {
            get { return _RoleName; }
            set { _RoleName = value; }
        }
        /// <summary>
        /// 主键，自动编号
        /// </summary>
        public int ID
        {
            get { return _ID; }
            set { _ID = value; }
        }
        #endregion

        #region 方法列表

        #region 教育局角色查询
        /// <summary>
        /// 返回教育局角色列表
        /// </summary>
        /// <param name="isDisable">0正常1禁用 2全部</param>
        /// <returns></returns>
        public DataTable GetEduRoleList(int isDisable)
        {
            string sql = "";
            switch (isDisable)
            {
                case 0:
                    sql = "select * from EduRole where IsDisable =0";
                    break;
                case 1:
                    sql = "select * from EduRole where IsDisable =1";
                    break;
                case 2:
                    sql = "select * from EduRole";
                    break;
                default:
                    sql = "select * from EduRole";
                    break;
            }

            DataTable dt = DBAction.GetDTFromSQL(sql);
            return dt;
        }

        /// <summary>
        /// 根据ID查询教育局角色
        /// </summary>
        /// <param name="eduID">角色编号</param>
        /// <returns>查询成功返回true,否则返回false</returns>
        public bool GetEduRoleByID(int eduID)
        {
            DataTable dt = DBAction.GetDTFromSQL("Select * From " + ETableName.EduRole + " where id=" + eduID);
            if (dt.Rows.Count < 1)
            {
                return false;
            }
            this._ID = eduID;
            this._RoleName = Convert.ToString(dt.Rows[0]["RoleName"]);
            this._RolePM = Convert.ToString(dt.Rows[0]["RolePM"]);
            this._IsDisable = Convert.ToBoolean(dt.Rows[0]["IsDisable"]);
            return true;
        }
        #endregion

        #region 添加教育局角色
        /// <summary>
        /// 添加教育局角色
        /// </summary>
        /// <returns>添加成功返回true,否则返回false</returns>
        public bool AddEduRole()
        {
            RParams RP = new RParams();
            RP.Add("RoleName", this._RoleName, SqlDbType.VarChar);
            RP.Add("RolePM", this._RolePM, SqlDbType.VarChar);
            RP.Add("IsDisable", this._IsDisable, SqlDbType.Bit);
            return AddEduRole(RP);
        }
        /// <summary>
        /// 添加教育局角色
        /// </summary>
        /// <param name="RP">数据集</param>
        /// <returns>添加成功返回true,否则返回false</returns>
        public bool AddEduRole(RParams RP)
        {
            return DBAction.Insert(ETableName.EduRole, RP);
        }
        #endregion

        #region 修改教育局角色
        /// <summary>
        /// 修改教育局角色
        /// </summary>
        /// <returns>修改成功返回true,否则返回false</returns>
        public bool MdfEduRole()
        {
            RParams RP = new RParams();
            RP.Add("ID", this._ID, SqlDbType.Int);
            RP.Add("RoleName", this._RoleName, SqlDbType.VarChar);
            RP.Add("RolePM", this._RolePM, SqlDbType.VarChar);
            RP.Add("IsDisable", this._IsDisable, SqlDbType.Bit);
            string colFields = "RoleName,RolePM,IsDisable";
            string whereFields = "ID=@ID";
            return MdfEduRole(colFields, whereFields, RP);
        }
        /// <summary>
        /// 修改教育局角色
        /// </summary>
        /// <param name="colFields">修改的列</param>
        /// <param name="whereFields">修改条件</param>
        /// <param name="RP">数据集</param>
        ///  <returns>修改成功返回true,否则返回false</returns>
        public bool MdfEduRole(string colFields, string whereFields, RParams RP)
        {
            return DBAction.Update(ETableName.EduRole, colFields, whereFields, RP);
        }
        #endregion

        #region 根据ID删除角色
        /// <summary>
        /// 根据ID删除角色
        /// </summary>
        /// <param name="eduID">角色ID</param>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelEduRole(int eduID)
        {
            RParams RP = new RParams();
            RP.Add("ID", eduID, SqlDbType.Int);
            string whereFields = "ID=@ID";
            return DBAction.Delete(ETableName.EduRole, whereFields, RP);
        }
        /// <summary>
        /// 根据ID删除角色
        /// </summary>
        /// <returns>删除成功返回true,否则返回false</returns>
        public bool DelEduRole()
        {
            return DelEduRole(this._ID);
        }
        #endregion

        #endregion
    }
}
